package com.csu.letaobackend.controllerM;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csu.letaobackend.commom.CommonResponse;
import com.csu.letaobackend.commom.GlobalFormDateConvert;
import com.csu.letaobackend.serviceM.StatisticsMService;
import com.csu.letaobackend.vo.BrowsingrecordVO;
import com.csu.letaobackend.vo.CategorySellVO;
import com.csu.letaobackend.vo.IncomeVO;
import com.csu.letaobackend.vo.ShopSellVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("/admin/statistics")
public class StatisticsMController {

      @Autowired
      StatisticsMService statisticsMService;

      @Autowired
      GlobalFormDateConvert globalFormDateConvert;

      @GetMapping("/day/income")
      @ResponseBody
      CommonResponse<IncomeVO> getDayIncome() {
            return statisticsMService.getDayIncome();
      }


      @GetMapping("/week/income")
      @ResponseBody
      CommonResponse<IncomeVO> getWeekIncome() {
            return statisticsMService.getWeekIncome();
      }


      @GetMapping("/month/income")
      @ResponseBody
      CommonResponse<IncomeVO> getMonthIncome() {
            return statisticsMService.getMonthIncome();
      }


      @GetMapping("/year/income")
      @ResponseBody
      CommonResponse<IncomeVO> getYearIncome() {
            return statisticsMService.getYearIncome();
      }

      @GetMapping("/users")
      @ResponseBody
      CommonResponse getUserNum() {
            return statisticsMService.getUserNum();
      }

      @GetMapping("/sellers")
      @ResponseBody
      CommonResponse getSellerNum() {
            return statisticsMService.getSellerNum();
      }

      @GetMapping("/shops")
      @ResponseBody
      CommonResponse getShopNum() {
            return statisticsMService.getShopNum();
      }

      @GetMapping("/items")
      @ResponseBody
      CommonResponse getItemNum() {
            return statisticsMService.getItemNum();
      }

      @GetMapping("/week/refund")
      @ResponseBody
      CommonResponse getWeekRefund() {
            return statisticsMService.getWeekRefund();
      }

      @GetMapping("/year/refund")
      @ResponseBody
      CommonResponse getYearRefund() {
            return statisticsMService.getYearRefund();
      }

      @GetMapping("/week/orders")
      @ResponseBody
      CommonResponse getWeekOrderNum() {

            return statisticsMService.getWeekOrderNum();
      }

      @GetMapping("/year/orders")
      @ResponseBody
      CommonResponse getYearRefundNum() {

            return statisticsMService.getYearRefundNum();
      }

      @GetMapping("/year/categorysellnum")
      @ResponseBody
      CommonResponse<List<CategorySellVO>> getCategorySell() {
            return statisticsMService.getCategorySell();
      }

      @GetMapping("/year/shopsellnum")
      @ResponseBody
      CommonResponse<List<ShopSellVO>> getShopSell() {
            return statisticsMService.getShopSell();
      }


      @GetMapping("/browsingrecords/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<BrowsingrecordVO>> getRecords(@PathVariable int pageid, @PathVariable int pagesize) {
            return statisticsMService.getRecords(pageid, pagesize);
      }


      @GetMapping("/username/{username}/time/{time}/browsingrecords/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<BrowsingrecordVO>> searchRecords(@PathVariable String username, @PathVariable String time,
                                                            @PathVariable int pageid, @PathVariable int pagesize) {
            Date date = globalFormDateConvert.convert(time.replace("T", " "));
            return statisticsMService.searchRecords(username, date, pageid, pagesize);
      }
}
